package com.liuanbang.saro.sarodemo.ui.activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RadioGroup;

import com.liuanbang.saro.sarodemo.R;
import com.liuanbang.saro.sarodemo.base.BaseActivity;
import com.liuanbang.saro.sarodemo.util.ToastUtils;

/**
 * Created by Saro on 2017/2/7.
 */

public class NotificationActivity extends BaseActivity {

    private RadioGroup mOptionGroup;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_notification);
        mOptionGroup = (RadioGroup) findViewById(R.id.options_group);

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    public Toolbar getToolbar() {
        return null;
    }

    public void onPostClick(View view) {
        int noteId = mOptionGroup.getCheckedRadioButtonId();
        Notification note;
        switch (noteId) {
            case R.id.option_basic:
            case R.id.option_bigtext:
            case R.id.option_bigpicture:
            case R.id.option_inbox:
                note = buildNotification(noteId);
                break;
            case R.id.option_private:
            case R.id.option_secret:
            case R.id.option_headsup:
                note=buildeSecuredNotification(noteId);
                default:
                    throw new IllegalArgumentException("什么鬼");
        }

        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        manager.notify(noteId,note);
    }

    private Notification buildNotification(int type) {
        Intent launchIntent = new Intent(this, NotificationActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);

        //使用发送的时间创建通知
        NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);

        builder.setSmallIcon(R.drawable.ic_beiyong)
                .setTicker("哈哈 发生什么了")
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setContentTitle("完成啦")
                .setContentText("点击这里！")
                .setContentIntent(contentIntent);

        switch (type){
            case R.id.option_basic:
                ToastUtils.showToast("4");
                //返回简单的通知
                return builder.build();
            case R.id.option_bigtext:
                //包括两个动作
                builder.addAction(android.R.drawable.ic_menu_call,"电话",contentIntent);
                builder.addAction(android.R.drawable.ic_menu_recent_history,"历史纪录",contentIntent);

                //在展开时使用BigTextStyle
                NotificationCompat.BigPictureStyle textStyle = new android.support.v4.app.NotificationCompat.BigPictureStyle(builder);

                textStyle.setBigContentTitle("ha shaj dhs耗时间多久啊等哈 还等哈就等哈会撒谎的骄傲活动时间啊火红的萨建华大街是大神还是打睡大觉啥叫好大事记");
                ToastUtils.showToast("1");
                return textStyle.build();
            case R.id.option_bigpicture:

                //添加一個額外動作
                builder.addAction(android.R.drawable.ic_menu_compass,"View 位置",contentIntent);
                //在展開時使用BigPictureStyle
                NotificationCompat.BigPictureStyle pictureStyle = new android.support.v4.app.NotificationCompat.BigPictureStyle(builder);
                pictureStyle.bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.ic_beiyong));
                ToastUtils.showToast("2");
                return pictureStyle.build();
            case R.id.option_inbox:
                //在展開時使用InbocStyle
                NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle(builder);
                inboxStyle.setSummaryText("4 new tasks");
                inboxStyle.addLine("晚飯");
                inboxStyle.addLine("蘋果");
                inboxStyle.addLine("西瓜");
                inboxStyle.addLine("收起來");
                ToastUtils.showToast("3");
                return inboxStyle.build();
            default:
                //为啥这里主调就报错呢
                throw  new IllegalArgumentException("buzhidao");
        }
    }

    private Notification buildeSecuredNotification(int type){
        Intent launchIntent = new Intent(this, NotificationActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);

        //構造基本通知
         android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_beiyong)
                .setContentTitle("Account Balance Update")
                .setContentText("哈哈哈 沒有事")
                .setStyle(new NotificationCompat.BigTextStyle().bigText("hahahahasdahjdias 湖師大還等哈多還是大家愛蝴蝶結安頓好愛好的驕傲和大家撒謊愛好的撒回到家安徽的安頓好驕傲是撒大家"))
                .setContentIntent(contentIntent);

        switch (type){
            case R.id.option_private:
                //為安全鎖定的提供獨特版本通知
                Notification publicNote = new Notification.Builder(this)
                        .setSmallIcon(R.drawable.ic_beiyong)
                        .setContentTitle("Account Notifition")
                        .setContentText("什麼玩意")
                        .setContentIntent(contentIntent)
                        .build();
                return builder.setPublicVersion(publicNote).build();
            case R.id.option_secret:
                //
                return builder.setVisibility(Notification.VISIBILITY_SECRET).build();
            case R.id.option_headsup:

                return builder.setDefaults(Notification.DEFAULT_SOUND)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .build();
            default:
                throw  new IllegalArgumentException("什麼鬼");
        }
    }
}
